<extend name="Base/base" />
<block name='head'>
    <meta charset="utf-8">
    <link href="/Public/static/dropload/dropload.css" rel="stylesheet" />
    <link href="/Public/Index/css/workdiary.css" rel="stylesheet" />
    <style type="text/css">
        .search{
            height:45px;
            line-height: 45px;
            border:1px solid #CFDDEA;
            font-size:1.5rem;
            background:white;
        }
        .type{
            float:left;
        }
        .textarea{
            height: 35px;
            border: 1px solid #CFDDEA;
            width: 200px;
            margin-top: 3px;
        }
    </style>
</block>
<block name="content" > 
    <div class="transferred_table">
        <table border="1" class='newdata'>
            <notempty name="lists">
                <foreach name="lists" item="diary">
                    <tr>
                        <td width='25%'><a href="{:U('show',array('id'=>$diary['dia_id']))}">{$diary.dia_date}</a></td>
                        <td><a href="{:U('show',array('id'=>$diary['dia_id']))}">{$diary.user_name}</a></td>
                        <if condition="$diary['user_id'] eq $diary['session_user']">
                            <td ><a href="{:U('editDiary',array('dia_id'=>$diary['dia_id']))}">编辑</a> | <a class='pointer delDiary' data-id="{$diary['dia_id']}">删除</a></td>
                        <else />
                            <td ><a href="{:U('commentDiary',array('dia_id'=>$diary['dia_id']))}">评论</a>
                        </if>
                    </tr>
                </foreach>
            <else />
                <tr><td colspan="5" style="text-align: left">暂无数据</td></tr>
            </notempty>
        </table>
        <!--<div class="page">{$pages}</div>-->
        <input type="hidden" id="user_id" value="{$diary.user_id}">
        <input type="hidden" id="url" value="{:U('dropload')}">
        <input type="hidden" id="delurl" value="{:U('Diary/delDiary')}">
    </div>
    <div class="button">
        <a class="am-btn back" data-url="{:U('userLists')}">返 回</a>
    </div>
</div>
</block>
<block name="script">
    <script type="text/javascript" src="/Public/static/dropload/dropload.js" ></script>
    <script type="text/javascript" src="/Public/Index/js/form.js"></script>
    <script type="text/javascript" src="/Public/Index/js/diary.js"></script>
    <script type="text/javascript">
        $('.back').on('click', function () {
            location.href = $(this).attr('data-url')
        })

        $(initDelDiary());

        $(function () {
            p = 2;
            var dropload = $('.transferred_table').dropload({
                scrollArea: window,
                domDown: {
                    domClass: 'dropload-down',
                    domRefresh: '<div class="dropload-refresh">上拉加载更多</div>',
                    domLoad: '<div class="dropload-load"><span class="loading"></span>加载中...</div>',
                    domNoData: '<div class="dropload-noData">已无数据</div>'
                },
                loadDownFn: function (me) {
                    var user_id = $('#user_id').val();
                    var url = $('#url').val() + '?p=' + p + "&user_id=" + user_id;
//                    alert(user_id);
                    p++;
                    $.ajax({
                        url: url,
                        type: 'get',
                        success: function (res) {
                            console.log(res)
//                            alert(res.length);
                            if (res.length > 0) {
                                var html = '';
                                for (var i = 0; i < res.length; i++) {
                                    html += '<tr><td><a href="/Index/Diary/show/id/'+res[i].dia_id+'">' + res[i].dia_date + '</a></td>';
                                    html += '<td><a href="/Index/Diary/show/id/'+res[i].dia_id+'">'+res[i].user_name+'</a></td>';
                                    if(res[i].user_id == res[i].session_user){
                                        html += '<td><a href="/Index/Diary/editDiary/dia_id/'+res[i].dia_id+'">编辑</a> | <a class="pointer delDiary" data-id='+res[i].dia_id+'>删除</a></td>';
                                    }else{
                                        html += '<td><a href="/Index/Diary/commentDiary/dia_id/'+res[i].dia_id+'">评论</a></td>';
                                    }
                                }
                                $('.transferred_table tr:last').after(html);
                            } else {
                                me.noData();
                            }
                            me.resetload();
                        }
                    })
                }
            });
        })
        $.ajax()
    </script>
</block>
